﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Barebones.Framework;
using Barebones.Components;

namespace Barebones.Xna
{
    public class BarebonesComponent : DrawableGameComponent
    {
        Engine m_Engine = new Engine();

        public BarebonesComponent(Game game, GraphicsDeviceManager manager, params EngineComponent[] items)
            : base(game)
        {
            foreach (EngineComponent component in items)
                m_Engine.AddComponent(component);

            m_Engine.Forum.Fire<CreatedMessage>(new CreatedMessage() { Game = game, Manager = manager });
        }

        public override void Initialize()
        {
            base.Initialize();

            m_Engine.Forum.Fire<InitializeMessage>(new InitializeMessage() { Device = GraphicsDevice });
        }

        protected override void LoadContent()
        {
            m_Engine.Forum.Fire<LoadContentMessage>(new LoadContentMessage() { Device = GraphicsDevice, Content = Game.Content });

            base.LoadContent();
        }

        public override void Update(GameTime gameTime)
        {
            m_Engine.Update((float)gameTime.ElapsedGameTime.TotalSeconds);

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            m_Engine.Draw();

            base.Draw(gameTime);
        }
    }
}
